﻿package mortal.game.view.copy.QuestionCopy.panel
{
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.copy.QuestionCopy.item.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class QuestionCopyPassWin extends BaseWindow
    {
        protected var _bg:GImageBitmap;
        protected var _recodeTxt:GTextFiled;
        protected var _okBtn:GButton;
        protected var _linkBtn:GButton;
        protected var _rewadList:CellsGridSprite;
        protected var _expNum:GTextFiled;
        protected var _tips1:GTextFiled;
        protected var _tips2:GTextFiled;
        private var _isUILoad:Boolean = false;
        private var _mask:GSprite;
        private static var _instance:QuestionCopyPassWin;

        public function QuestionCopyPassWin(param1:ILayer = null)
        {
            this.layer = LayerManager.fullScreenLayer;
            this.setSize(383, 500);
            this.title = "" + Language.getString(70962);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.questionCopy, this.onShowWin);
            return;
        }// end function

        private function onShowWin() : void
        {
            this._isUILoad = true;
            this._bg = UIFactory.gImageBitmap(ImagesConst.QuestionCopyInfoBg, 9, 39, this);
            this._recodeTxt = UIFactory.gTextField("" + Language.getString(70963), 106, 49, 100, 25, this, GlobalStyle.textFormatHuang2.setSize(15).setBold(true));
            this._okBtn = UIFactory.gButton("" + Language.getString(70964), 157, 467, 57, 27, this);
            this._linkBtn = UIFactory.gButton("" + Language.getString(70965), 305, 429, 100, 30, this, "GreenLinkButton");
            this._rewadList = UIFactory.getUICompoment(CellsGridSprite);
            this._rewadList.colNum = 1;
            this._rewadList.vCellWid = 100;
            this._rewadList.hCellWid = 70;
            this._rewadList.genCellFun = UIFactory.getUICompoment;
            this._rewadList.genCells(4, QuestionCopyRender);
            this._rewadList.x = 24;
            this._rewadList.y = 153;
            this.addChild(this._rewadList);
            this._expNum = UIFactory.gTextField("3000", 106, 76, 100, 20, this, GlobalStyle.textFormatHuang2.setSize(15).setBold(true));
            this._tips1 = UIFactory.gTextField("" + Language.getString(70966), 13, 417, 100, 20, this, GlobalStyle.textFormatLv.setBold(true));
            this._tips2 = UIFactory.gTextField("" + Language.getString(70967), 13, 435, 318, 20, this, GlobalStyle.textFormatLv.setBold(true));
            this._okBtn.label = "" + Language.getString(60264);
            this._okBtn.configEventListener(MouseEvent.CLICK, this.closeBtnClickHandler);
            this._linkBtn.configEventListener(MouseEvent.CLICK, this.rechargeHd);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            LoaderHelp.removeResEvent(ResFileConst.questionCopy, this.onShowWin);
            if (this._isUILoad == false)
            {
                return;
            }
            _closeBtn.visible = true;
            this._isUILoad = false;
            super.disposeImpl(param1);
            this._bg = null;
            this._recodeTxt = null;
            this._okBtn = null;
            this._linkBtn = null;
            this._rewadList = null;
            this._expNum = null;
            this._tips1 = null;
            this._tips2 = null;
            if (this._mask)
            {
                this._mask.graphics.clear();
                this._mask.dispose();
                this._mask = null;
            }
            return;
        }// end function

        public function updatePass(param1:Object) : void
        {
            var _loc_4:QuestionCopyRender = null;
            var _loc_5:Object = null;
            var _loc_6:Array = null;
            var _loc_7:int = 0;
            var _loc_8:BaseItem = null;
            var _loc_9:SPlayerItem = null;
            this._recodeTxt.text = "" + param1.score;
            this._expNum.text = "" + param1.exper;
            var _loc_2:* = QuestionCopyConfig.instance().getWorldLevelRewardsObj();
            this._rewadList.genCells(_loc_2.length, QuestionCopyRender);
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                _loc_4 = this._rewadList.cellArr[_loc_3];
                _loc_5 = _loc_2[_loc_3];
                if (_loc_4)
                {
                    _loc_6 = QuestionCopyConfig.instance().getRewardItems(_loc_5.itemRewards);
                    _loc_7 = 0;
                    while (_loc_7 < _loc_6.length)
                    {
                        
                        _loc_8 = _loc_4.cellSp.cellArr[_loc_7];
                        _loc_4.updateScore(_loc_5.scoreMin, _loc_5.scoreMax);
                        _loc_9 = _loc_6[_loc_7];
                        if (_loc_8)
                        {
                            _loc_8.itemData = new ItemData(_loc_9);
                        }
                        _loc_7++;
                    }
                }
                _loc_3++;
            }
            return;
        }// end function

        override protected function closeBtnClickHandler(event:MouseEvent) : void
        {
            hide();
            if (this._mask)
            {
                this._mask.graphics.clear();
                this._mask.dispose();
                this._mask = null;
            }
            if (Cache.instance.question.isOverFlag)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyLeave));
            }
            return;
        }// end function

        private function rechargeHd(event:MouseEvent) : void
        {
            GameUtil.gotoRecharge(ModuleTypeConst.QuestionCopyPassWin);
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            param1 = (SceneRange.display.width - this.width) / 2 + 60;
            param2 = (SceneRange.display.height - this.height) / 2 + 30;
            if (this.darkMask)
            {
                (layer as DisplayObjectContainer).addChild(this.darkMask);
            }
            this.stageResize();
            super.show(param1, param2);
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            if (this.darkMask != null)
            {
                this.darkMask.cacheAsBitmap = true;
                DisplayUtil.drawFullScreenMask(this.darkMask);
            }
            return;
        }// end function

        protected function get darkMask() : GSprite
        {
            if (this._mask == null)
            {
            }
            return this._mask;
        }// end function

        public static function get instance() : QuestionCopyPassWin
        {
            if (_instance == null)
            {
                _instance = new QuestionCopyPassWin;
            }
            return _instance;
        }// end function

    }
}
